package com.atguigu.zqkutils;

import com.atguigu.bean.User;
import com.atguigu.utils.JDBCUtils;
import org.junit.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Date:2020/8/28
 * Author:ybc
 * Description:
 */
public class ZqkJDBCUtilsTest {
    @Test
    public void testJDBCUTils() {
        Connection connection = null;
        connection = JDBCUtils.getConnection();
        PreparedStatement ps = null;
        ResultSet rs = null;
        List<User> list = new ArrayList<User>();

        try {
             connection = JDBCUtils.getConnection();
             ps = connection.prepareStatement("select *from t_user");
             rs = ps.executeQuery();

            while (rs.next()) {
                User user = new User(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getInt(5));
                list.add(user);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            JDBCUtils.closeConnection(connection);
        }
        for (User user : list) {
            System.out.println(user);
        }


    }
}
